/**
 * Created by qingteng.wang on 2017/1/9.
 */


+function($){
    $(function(){
        const $window = $(window);
        const $banner = $('#banner');
        const $khNav = $('#khNav');
        const $khNavA = $khNav.find('a');
        const $swiperWrap = $banner.find('.swiper-wrapper');
        const $slide = $banner.find('.swiper-slide');
        const locationHrefStr = $window[0].location.href;
        let swiperTimerId = null;
        let windowW = $window.width();
        let height = windowW*(640/1920);

        $banner.height(height);

        const khtSwiper = new Swiper('#banner',{
            pagination : '.pagination',
            speed : 800,
            mousewheelControl : false,
            noSwiping:true,
            autoResize:true,
            resizeReInit:true,
            paginationClickable :true,
            autoplay : 5000,
            loop : true,
            onSwiperCreated (swiper){
                swiper.support.touch && $slide.removeClass('swiper-no-swiping');
            }
        });

        $window.on('resize',(e)=>{
            swiperTimerId && clearTimeout(swiperTimerId);
            swiperTimerId = setTimeout(()=>{
                windowW = $window.width();
                height = windowW*(640/1920);
                $banner.height(height);
            },1000/60);

        });


        $khNavA.each((i,nava)=>{
            const $nava = $(nava);
            const hrefStr = $nava.attr('href');
            const hrefRef = new RegExp(hrefStr);
            hrefRef.test(locationHrefStr) && $nava.parent().addClass('active');
        });
        const regWeb = /web\/$/;
        if(regWeb.test(locationHrefStr) ){
            $khNavA.eq(0).parent().addClass('active');
        }
    })
}(jQuery);